Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
How to set headers of stream response so I can infer then on next stream.on("data", ()=>{}) handler in Node.js?

Background: I am trying to be able to make some unique identifier for each client that connects and stream to my service such that whenever they make a new request I can detect and block them from restreaming from my site until they stop the current stream.

DISCLAIMER: I am new to streaming, I was hoping that maybe on the New request object somewhere I would be able to tall if a user is streaming. I think somehow this is can be for socket application

Bellow is my code so far. The idea is to somehow be able to tell how many stream each client(Broswer) is streaming on each time they send request to my server.

app.get('/video', function (req, res) {

  const path = 'abc.mp4'
  const stat = fs.statSync(path)
  const fileSize = stat.size
  const range = req.headers.range

  if (range) {
    // console.log("Has range: ", range)
    const parts = range.replace(/bytes=/, "").split("-")
    const start = parseInt(parts[0], 10)
    const end = parts[1]
      ? parseInt(parts[1], 10)
      : fileSize - 1

    const chunksize = (end - start) + 1
    const file = fs.createReadStream(path, { start, end })

    const head = {
      'Content-Range': `bytes ${start}-${end}/${fileSize}`,
      'Accept-Ranges': 'bytes',
      'Content-Length': chunksize,
      'Content-Type': 'video/mp4',
      'MY_UNIQUE_ID': "Hello World" + new Date().toISOString()
    }



    res.writeHead(206, head)

    file.pipe(res)

    file.on("data", function (chunk) {
      if (!!req.headers) {
        //Expecting to also have MY_UNIQUE_ID
        console.log(req.headers)
      }
    });

  }
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!